package com.lsax.filter;

import org.slf4j.MDC;
import org.springframework.cloud.sleuth.instrument.web.TraceFilter;
import org.springframework.core.annotation.Order;
import org.springframework.web.util.UrlPathHelper;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Order(TraceFilter.ORDER-1)
public class SleuthFilter implements Filter {

    private UrlPathHelper urlPathHelper = new UrlPathHelper();

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        /*HttpServletRequest req = (HttpServletRequest) request;
        String uri = this.urlPathHelper.getPathWithinApplication(req);
        MDC.put("X-Url",uri);
        // 获取请求是从哪里来的
        String referer = req.getHeader("referer");
        MDC.put("X-Caller",referer);
        chain.doFilter(request, response);
        return;*/
    }

    @Override
    public void destroy() {

    }
}
